package no.uials.distsys;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.Map;

/**
 *
 * @author Anders
 */
public class WarehouseSystem extends UnicastRemoteObject implements UserService, AdminService {
    private Warehouse warehouse;
    
    
    /**
     * 
     * @param warehouse
     * @throws RemoteException 
     */
    public WarehouseSystem(Warehouse warehouse) throws RemoteException {
        this.warehouse = warehouse;
    }

    /**
     * 
     * addArticle()
     * 
     * @param name
     * @param price
     * @param stock
     * @param pos
     * @return
     * @throws RemoteException 
     */
    @Override
    public Article addArticle(String name, double price, int stock, Position pos) throws RemoteException {
        return warehouse.addArticle(name, price, stock, pos);
    }

    /**
     * 
     * addArticle()
     * 
     * @param name
     * @param price
     * @param stock
     * @param aisle
     * @param section
     * @param shelf
     * @return
     * @throws RemoteException 
     */
    @Override
    public Article addArticle(String name, double price, int stock, int aisle, int section, int shelf) throws RemoteException {
        return warehouse.addArticle(name, price, stock, aisle, section, shelf);
    }

    /**
     * 
     * removeArticle()
     * 
     * @param ID
     * @return
     * @throws DistSysException
     * @throws RemoteException 
     */
    @Override
    public Article removeArticle(String ID) throws DistSysException, RemoteException {
        return warehouse.removeArticle(ID);
    }

    /**
     * 
     * changeStock()
     * 
     * @param article
     * @param number
     * @return
     * @throws RemoteException 
     */
    @Override
    public int changeStock(Article article, int number) throws RemoteException {
        return warehouse.updateStock(article, number);
    }

    /**
     * 
     * listOrders()
     * 
     * @return
     * @throws RemoteException 
     */
    @Override
    public Map<Integer, Order> listOrders() throws RemoteException {
        return warehouse.getAllOrders();
    }

    /**
     * 
     * getArticles()
     * 
     * @return
     * @throws RemoteException 
     */
    @Override
    public Map<String, Article> getArticles() throws RemoteException {
        return warehouse.getArticles();
    }

    /**
     * 
     * placeOrder()
     * 
     * @param user
     * @param order
     * @return
     * @throws DistSysException
     * @throws RemoteException 
     */
    @Override
    public int placeOrder(User user, Map<String, OrderLine> order) throws DistSysException, RemoteException {
        return warehouse.placeOrder(user, order);
    }

    /**
     * 
     * getUserOrders()
     * 
     * @param user
     * @return
     * @throws RemoteException 
     */
    @Override
    public Map<Integer, Order> getUserOrders(String user) throws RemoteException {
        return warehouse.getUserOrders(user);
    }
    
    /**
     * 
     * getUser()
     * 
     * @param user
     * @return
     * @throws RemoteException
     * @throws DistSysException 
     */
    @Override
    public User getUser(String user) throws RemoteException, DistSysException {
        return warehouse.getUser(user);
    }
}